package com.shfl.servermanage.logic.service.impl;


import com.shfl.servermanage.logic.bean.SysAttachment;
import com.shfl.servermanage.logic.mapper.SysAttachmentMapper;
import com.shfl.servermanage.logic.model.info.AddSingleAttachmentInfo;
import com.shfl.servermanage.logic.service.SysAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class SysAttachmentServiceImpl implements SysAttachmentService {

    @Autowired
    private SysAttachmentMapper sysAttachmentMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertSelective(SysAttachment record) {
        return sysAttachmentMapper.insertSelective(record);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addSingle(AddSingleAttachmentInfo info) {
        // 删除原来的附件
        sysAttachmentMapper.removeByRelationIdAndAttachType(info.getRelationId(), info.getAttachType());
        if (info.getId() == null) {
            return;
        }
        // 启用附件
        sysAttachmentMapper.enableSingle(info);
    }

    @Override
    public List<SysAttachment> findByMap(Map<String, Object> objectMap) {
        return sysAttachmentMapper.findByMap(objectMap);
    }
}
